n = int(input())

for _ in range(n):
    num = input()
    num = int(num,16)
    print("{}".format(oct(num)[2:]))
